import pymysql

class Sql(object):
    def output_sql(self,all_data):
            conn = pymysql.Connect(
                host = "127.0.0.1",
                port = 3306,
                user = 'root',
                passwd = '123456',
                db = 'data_collection',
                charset = 'utf8'
            )
            cursor = conn.cursor()
            sql_insert = "insert into policy " \
                         "(Title, Time, Content , Type ) value('%s', '%s','%s','%s')" \
                         % (all_data['Title'] , all_data['Time'] , all_data['Content'] , all_data['Type'])
            try:
                cursor.execute(sql_insert)
                conn.commit()
                print(cursor.rowcount)

            except Exception as e:
                print(e)
                #回滚
                conn.rollback()
            cursor.close()
            conn.close()
